package com.main.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.main.pojo.Award;

@Transactional
@Repository
public class AwardDAOImpl implements AwardDAO{

	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Award> getAward(String type) throws Exception {
		try {
			String hql = "FROM Award a WHERE a.active = 1 AND a.type = :type ORDER BY a.rank";
			Query query = sessionFactory.getCurrentSession().createQuery(hql);
			query.setString("type", type);
			return query.list();
		} catch (Exception e) {
			throw e;
		}
	}

}
